<?php 
	function getMembers()
	{

		$q = mysql_query("SELECT * FROM account, characters WHERE characters.aid = account.id AND account.grade > 0 ORDER BY characters.name ASC");

		$i = 1;
		echo '<table>';
		echo '<tr>
				<td width="20"><b>#</b></td>
				<td width="80"><b>Name</b></td>
				<td width="30"><b>Level</b></td>
				<td width="100"><b>Experience</b></td>
				<td width="70"><b>Missions</b></td>
				<td width="40"><b>Kills</b></td>
				<td width="60"><b>Deaths</b></td>
				<td width="100"><b>Pollars</b></td>
				<td><b>K/D Ratio</b></td>
			</tr>';

		if(!isset($_GET['search']))
		{
			
			while($f = mysql_fetch_array($q))
			{
				$wins = $f['wins'];
				$losses = $f['losses'];

				if($losses == 0)
				{
					if($wins == 0)
					{
						$kd = -0;
					}
					else
					{
						$kd = $wins;
					}
				}
				else if($wins == 0)
				{
					if($losses == 0)
					{
						$kd = 0;
					}
					else
					{
						$kd = 1/$losses;
					}
				}
				else
				{
					$kd = $wins/$losses;
				}


				if(!isset($_SESSION['user']) || $f['username'] != $_SESSION['user'])
				{
					echo '
						<tr>
							<td>'.$i.'</td>';

						if(!isset($_SESSION['user']))
						{
							echo '<td>'.$f['name'].'</td></a>';
						}
						else
						{
							echo '<td><a href="?page=profile&id='.$f['id'].'">'.$f['name'].'</a></td>';
						}

							echo'
							<td>'.$f['level'].'</td>
							<td>'.$f['xp'].'</td>
							<td>'.$f['finished_missions'].'</td>
							<td>'.$f['wins'].'</td>
							<td>'.$f['losses'].'</td>
							<td>'.($f['pollars']+$f['pank']).'</td>
							<td>'.round($kd, 2).'</td>
						</tr>
						';
					$i++;
				}

			}
			echo '</table>';

		}else{

			$name = $_GET['search'];
			$q = mysql_query("SELECT * FROM account, characters WHERE characters.aid = account.id AND account.grade > 0 AND characters.name LIKE '%$name%' ORDER BY characters.name ASC");
			while($f = mysql_fetch_array($q))
			{
				$wins = $f['wins'];
				$losses = $f['losses'];

				if($losses == 0)
				{
					if($wins == 0)
					{
						$kd = -0;
					}
					else
					{
						$kd = $wins;
					}
				}
				else if($wins == 0)
				{
					if($losses == 0)
					{
						$kd = 0;
					}
					else
					{
						$kd = 1/$losses;
					}
				}
				else
				{
					$kd = $wins/$losses;
				}


				if(!isset($_SESSION['user']) || $f['username'] != $_SESSION['user'])
				{
					echo '
						<tr>
							<td>'.$i.'</td>';

						if(!isset($_SESSION['user']))
						{
							echo '<td>'.$f['name'].'</td></a>';
						}
						else
						{
							echo '<td><a href="?page=profile&id='.$f['id'].'">'.$f['name'].'</a></td>';
						}

							echo'
							<td>'.$f['level'].'</td>
							<td>'.$f['xp'].'</td>
							<td>'.$f['finished_missions'].'</td>
							<td>'.$f['wins'].'</td>
							<td>'.$f['losses'].'</td>
							<td>'.($f['pollars']+$f['pank']).'</td>
							<td>'.round($kd, 2).'</td>
						</tr>
						';
					$i++;
				}

			}
			echo '</table>';

		}	

	}
?>